<?php
namespace Api;
use App\Controller;


// hook api_wechat_use.php

/**
 * @title   菜单
 * @rank    3
 */
class Wechat extends Controller
{
    // hook api_wechat_start.php

    /**
     * @title    微信验证
     * @rank    99
     */
    public function action_Valid()
    {
        // hook api_wechat_valid_start.php
        $echostr = $this->request->param('echostr', '');
        if (!empty($echostr)) {
            // hook api_wechat_valid_end.php
            $post = $this->request->param();

            $token = _CONF('WechatToken');
            $echoStr = $post['echostr'];
            $signature = $post['signature'];
            $timestamp = $post['timestamp'];
            $nonce = $post['nonce'];
            $tmpArr = array($token, $timestamp, $nonce);
            sort($tmpArr, SORT_STRING);
            $tmpStr = implode($tmpArr);
            $tmpStr = sha1($tmpStr);
            if ($tmpStr == $signature) {
                return $echoStr;
            }
            return "";
        } else {
            $data='';
            //$data = $this->WechatSdk->responseMsg($this->request->getContent());
            // hook api_wechat_valid_end.php
            return $data;
        }
    }

    // hook api_wechat_end.php

}

?>